import { watcher } from "@feng3d/watcher";
import { CylinderGeometry } from "../../thirdparty/three/imports";
import { BufferGeometry3D } from "../core/BufferGeometry3D";

export class CylinderGeometry3D extends BufferGeometry3D
{
    radiusTop = 1;
    radiusBottom = 1;
    height = 1;
    radialSegments = 32;
    heightSegments = 1;
    openEnded = false;
    thetaStart = 0;
    thetaLength = Math.PI * 2;

    get _geometry()
    {
        if (!this.__geometry)
        {
            this.__geometry = new CylinderGeometry(this.radiusTop, this.radiusBottom, this.height, this.radialSegments, this.heightSegments, this.openEnded, this.thetaStart, this.thetaLength);
        }

        return this.__geometry;
    }
    declare protected __geometry: CylinderGeometry;

    constructor()
    {
        super();
        watcher.watchs(this as CylinderGeometry3D, ["radiusTop", "radiusBottom", "height", "radialSegments", "heightSegments", "openEnded", "thetaStart", "thetaLength"], this._invalidate, this);
    }

    destroy()
    {
        watcher.unwatchs(this as CylinderGeometry3D, ["radiusTop", "radiusBottom", "height", "radialSegments", "heightSegments", "openEnded", "thetaStart", "thetaLength"], this._invalidate, this);
    }
}
